<!--
 * @Author: jiangjinchi 1468922694@qq.com
 * @Date: 2024-01-30 15:53:02
 * @LastEditors: jiangjinchi 1468922694@qq.com
 * @LastEditTime: 2024-12-17 10:04:39
 * @FilePath: \vue-admin-template\src\views\spareParts\warehouseManagement\components\searchTable.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <el-popover  :hide="hide" v-model="popVisible" width="700" trigger="click" placement="bottom">
      <div>
        <FBATable ref="countryTableRef" :data="tableData" height="300" :rowHeader="countryColumns"
          @rowClick="handleRowClick"></FBATable>
      </div>
      <el-input v-model="keyWords" @input="changeKey" slot="reference" placeholder="请选择内容"> </el-input>
    </el-popover>
  </div>
</template>
<script>
import { delay } from '@/utils/delay'
//   import { wfinFeeItemGetPageList } from '@/api/OverseasWarehouse/Cost'
import FBATable from './FBATable.vue'
export default {
  props: {
    temTableList: {
      type: Array
    },
    name: {
      type: String,
      default: ''
    },
    typeProp: {
      type: String,
      default: ''
    },
    index: {
      type: Number,
      default: () => 0
    },
    url: {
      type: String
    },
    checkId: {
      type:[Number,String]
    }
  },
  components: {
    FBATable
  },
  data() {
    return {
      pagination: {
        TotalCount: 0,
        PageIndex: 1,
        PageSize: 10
      },

      countryColumns: [
        {
          prop: 'name',
          label: '名称',
          align: 'center'
        },
        {
          prop: 'type',
          label: '类别',
          align: 'center'
        },
        {
          prop: 'code',
          label: '编号',
          align: 'center'
        },
        {
          prop: 'norm',
          label: '规格',
          align: 'center'
        },
        {
          prop: 'unit',
          label: '单位',
          align: 'center'
        },
        {
          prop: 'manufacturer',
          label: '厂家',
          align: 'center'
        },
        {
          prop: 'cnt',
          label: '安全库存',
          align: 'center'
        }
      ],
      popVisible: false,
      selected: [],
      timer: null,
      tableData: [],
      changeValue: '',
      needCheck:false,
      valList: ''

    }
  },
  created() {
    if (this.url == '/spar/stock-record/getInventoryList') {
      this.countryColumns.push({
        prop: 'num',
        label: '数量',
        align: 'center'
      })
    }
    // this.searchStore();
    this.tableData = this.temTableList;
  },
  computed: {
    keyWords: {
      get() {
        return this.name
      },
      set(val) {
        this.$emit('update:name', val)
      }
    }
  },

  watch: {

  },
  methods: {
    hide() {
       console.log('1')
    },
    searchStore() {
      this.$baseRequestGetParams(this.url, { name: '', norm: '' }, {}, 'get').then(res => {
        this.tableData = res.data;
      })
    },
    handleSelectionChange(val) {
      if (val.length >= 2) {
        let arrays = val.splice(0, val.length - 1)
        arrays.forEach(row => {
          this.$refs.countryTableRef.$refs.FBATable.toggleRowSelection(row) //除了当前点击的，其他的全部取消选中
        })
      }
      this.changeValue = val;
      this.$emit('selectedData', { list: val, index: this.index })
      this.timer = setTimeout(() => {
        this.popVisible = false
      }, 500)
    },
    handleRowClick(val) {
      this.changeValue = val;
      this.$emit('selectedData', { list: val, index: this.index })
      this.timer = setTimeout(() => {
        this.popVisible = false
      }, 200)
    },
    // 搜索
    changeKey(e) {
      this.needCheck = true;
      delay(() => {
        let params = {
          name: '',
          norm: ''
        }
        if (this.typeProp == 'norm') {
          params.norm = e
        } else {
          params.name = e;
        }
        this.$baseRequestGetParams(this.url, params, {}, 'get').then(res => {
          this.tableData = res.data;
        })
        this.$emit('clearContent',this.index)
      }, 200)
    },
    handleSizeChange(val) {
      this.pagination.PageSize = val
      // this.getList()
    },
    handleCurrentChange(val) {
      this.pagination.PageIndex = val
      // this.getList()
    }
  },
  destroyed() {
    clearTimeout(this.timer)
  }
}
</script>
<style lang="scss" scoped>
.demo-form-inline {
  position: relative;
  margin: 15px 10px;
}

.demo-footer {
  display: flex;
  justify-content: flex-end;
}

.country-footer {
  text-align: center;
  position: relative;
  margin: 10px auto;
}
</style>
  